package com.heima.admin.controller.v1;

import com.heima.admin.service.ChannerSevice;
import com.heima.api.admin.ChannelControllerApi;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ChannelController
 * @Description TODO
 * @Author AWei
 * @DATE 2021/4/9 17:58
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/channel")
public class ChannelController implements ChannelControllerApi {

    @Resource
    private ChannerSevice channerSevice;

    /**
     * @param channelDto 前端传来频道参数
     * @return 分页查询结果
     * @Description 分页查询频道信息或者根据名称分页查询
     */
    @Override
    @PostMapping("/list")
    public ResponseResult queryChannelByPageOrName(@RequestBody ChannelDto channelDto) {
        return channerSevice.queryChannelByPageOrName(channelDto);
    }

    /**
     * @param adChannel 新增的频道对象
     * @return 新增结果
     * @Description 新增频道信息
     */
    @Override
    @PostMapping("/save")
    public ResponseResult addChannel(@RequestBody AdChannel adChannel) {
        return channerSevice.addChannel(adChannel);
    }

    /**
     * @param adChannel 被修改对象
     * @return 修改结果
     * @Description 频道修改和频道有效无效设置
     */
    @Override
    @PostMapping("/update")
    public ResponseResult modifyChannel(@RequestBody AdChannel adChannel) {
        return channerSevice.modifyChannel(adChannel);
    }

    /**
     * @param id 被删除频道id
     * @return 删出结果
     * @Description 删除频道
     */
    @Override
    @GetMapping("/del/{id}")
    public ResponseResult deleteChannelById(@PathVariable("id") Integer id) {
        return channerSevice.deleteChannelById(id);
    }

    @Override
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = channerSevice.list();
        return ResponseResult.okResult(list);
    }
}
